#include <stdio.h>

#define TO_CHAR(x) (x + '0')
#define TO_NUM(x) (x - '0')
#define IS_DIG(x) (x >= '0' && x <= '9')
#define IS_ALP(x) (x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z')
#define NULL 0

int convert_to_digit(char x)
{
	if (x < 'Q'){
		return (x - 'A') / 3 + 2;
	}else {
		return (x - 'A' - 1) / 3 + 2;
	}
}

unsigned int get_hash_key(const char *str)
{
	int res = 0;
	int i = 0;
	while(str[i]){
		if ( IS_ALP(str[i]) ) {
			res *= 10;
			res += convert_to_digit(str[i]);
		} else if (IS_DIG(str[i])) {
			res *= 10;
			res += TO_NUM(str[i]);
		}
		i++;
	}
	return res;
}

typdef struct node {
	unsigned int key;
	int value;
	struct node* next;
} List;

List* find_node_in_list(List* L, unsigned int key)
{
	List *p = L;
	while (p != NULL) {
		if ( p->key == key ) {
			return p;
		}
		p = p-> next;
	}
	return p;
}

List* append_new_node_to_list(List** L, unsigned int key, int value)
{
	List *p = (List *)malloc(sizeof(List));
	p->next = *L;
	p->key = key;
	p->value = value;
	*L = p;
	return *L;
}

List* update_node_value_by_key(List* L, unsigned int key, int value)
{
	List *p = find_node_in_list(L, key);
	(p->value)++;
}

void destroy_list(List **L)
{
	List *p = *L;
	List *q = p;
	while(p){
		q = q->next;
		free(p);
		p = q;
	}
	*L = NULL;
}

typdef struct _Hash {
	List** _hash_array;
	int _array_size;
	int value_count;
} Hash;

Hash* init_hash(int hash_size)
{
	Hash *h = (Hash*) malloc(sizeof(Hash));
	h->_array_size = hash_size;
	h->value_count = 0;
	h->_hash_array = (List**)(malloc(sizeof(List*) * hash_size));
	memset(h->_hash_array, NULL, sizeof(List*) * hash_size);
}
List* get_node(Hash* h, unsigned int key)
{
	unsigned int real_key = key / (h->_array_size);
	List *L = h->_hash_array[real_key];
	List *node = find_node_in_list(L, key);
	return node;
}

Hash* update_value_hash(Hash* h, unsigned int key, int value)
{
	List *node = get_node(h, key);
	if ( node ) {
		node->value = value;
	} else {
		append_new_node_to_list(&node, key, value);
	}
}

int get_value(Hash* h, unsigned int key, int *is_ok)
{
	List* node = get_node(h, key);
	if (node) {
		*is_ok = 1;
		return node->value;
	}
	*is_ok = 0;
	return 0;
}

Hash* destroy_hash(Hash* h)
{
	
}


int main(int argc, char* argv[])
{
	int i = 1;
	char s[30];
	while (scanf("%s", s) == 1){
		printf("%u\n", get_hash_key(s));
	}
	return 0;
}


